<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2016/8/31 0031
  Time: 11:12
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%
  String path = request.getContextPath();
  String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<html>
<head>
  <base href="<%=basePath%>">
  <meta charset="utf-8"/>
  <title></title>
  <link rel="stylesheet" type="text/css" href="easyui-1.3.6/themes/default/easyui.css">
  <link rel="stylesheet" type="text/css" href="easyui-1.3.6/themes/icon.css">
  <link rel="stylesheet" type="text/css" href="easyui-1.3.6/demo/demo.css">
  <script type="text/javascript" src="easyui-1.3.6/jquery.min.js"></script>
  <script type="text/javascript" src="easyui-1.3.6/jquery.easyui.min.js"></script>
</head>
<body>
<%--<form action="rest/page/information/add" method="post" enctype="multipart/form-data">--%>
<%--<input name="publisherId" type="text"/> publisherName<br>--%>
<%--<input name="informationName" type="text"/>请输入文件名字<br>--%>
<%--<input name="informationContent" type="text"/>请输入文件内容<br>--%>
<%--<input name="jsonClass" type="text">--%>
<%--请选择这次要选的班级<br>--%>
<%--<input name="file" type="file"/>请选择文件<br>--%>
<%--<input value="提交" type="submit">--%>
<%--</form>--%>
<div class="row">
  <div class="col-md-12">
    <!-- BEGIN PAGE TITLE & BREADCRUMB-->
    <h3 class="page-title" id="index-page-title" style="font: normal 30px/0.8em '微软雅黑'">孜点教科</h3>
    <ul class="page-breadcrumb breadcrumb">
     <%-- <li>
        <i class="fa fa-home"></i>
        首页
        <i class="fa fa-angle-right"></i>
      </li>--%>
      <li>
        <%--<a href="javascript:;">--%>
        教学管理
        <%--</a>--%>
        <i class="fa fa-angle-right"></i>
      </li>
      <li>
        <%--<a href="javascript:;">--%>
        后台权限管理
        <%--</a>--%>
      </li>
    </ul>
    <!-- END PAGE TITLE & BREADCRUMB-->
  </div>
</div>


<input class="easyui-searchbox" data-options="prompt:'请输入教师id',searcher:doSearch" style="width:450px;height: 48px;background: transparent;border:none;">

<div style="margin:20px 0;"></div>
<div id="test" class="easyui-dialog" data-options="closed:true,modal:true,title:'是否要删除当前所选教师的角色'" style="width: 400px;">
  <div style="width:368px;height:160px;margin:auto;" >
     <a href="javascript:void(0)" class="easyui-linkbutton" onclick="delStudent()" style="display:inline-block;width:180px;height:30px;margin:65px 0px 0px 94px;line-height:30px;">确认删除当前所选教师的角色</a>
  </div>
</div>
<table id="dg" title="权限信息表" style="width:auto;height:auto" data-options="
				rownumbers:true,
				singleSelect:true,
				autoRowHeight:false,
				pagination:true,
				pageSize:10
				">
  <thead>
  <tr>
    <th field="teacherId" width="90">教师编号</th>
    <th field="teacherName" width="100">教师名字</th>
    <th field="teacherSex" width="50">教师性别</th>
    <th field="teacherIdCard" width="200">教师身份证号</th>
    <th field="teacherSchool" width="150">教师所在学校</th>
    <th field="teacherCollege" width="150">教师在属学院</th>
    <th field="roles" width="300">拥有角色</th>
  </tr>
  </thead>
</table>
<div id="test1" class="easyui-dialog" data-options="closed:true,modal:true,title:'添加教师的权限'" style="width:400px">
  <form id="ff" class="easyui-form" method="post" data-options="novalidate:true">
    <table style="margin:0px auto;margin-top: 20px;">
      <tr>
      <td>教师编号:</td>
        <td id="teacherId1" style="width:200px;height:30px;background-color:transparent;padding:0px 10px;margin: 5px 0px;"></td>
        <input type="hidden" name="teacherId" id="teacherId" >
      </tr>
      <tr>
        <td>教师名字:</td>
        <td id="teacherName" style="width:200px;height:30px;background-color:transparent;padding:0px 10px;margin: 5px 0px;"></td>
      </tr>
      <tr>
        <td>分配权限:</td>
        <td><select class="easyui-combobox" name="roleId" style="width:200px;height:30px;background-color:transparent;padding:0px 10px;margin: 5px 0px;">
          <option value="2" selected="selected">教师</option>
          <option value="3">管理员</option>
          <option value="4">领导</option>
          <option value="5">校长</option>
          <option value="6">院长</option>
          <%--<option value="7">课程组长</option>--%>
        </select></td>
      </tr>
    </table>
    <input type="hidden" value="${user.teacherid }" name="manageId">
  </form>
  <div style="text-align:center;padding:5px">
    <a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()" style="width:116px;height:30px;margin-bottom:20px;">确定</a>
  </div>
</div>
<script>
  var i = 1;
  function pagerFilter(data){
    if(i==1&&data[0]!=null){
      var to = data[0].total;
      var wh = data[0].wh;
    }else if(i==2&&data!=null){
      var to = data.total;
      var wh = data.wh;
    }else{
      var to = 0;
      var wh = "";
    }
    if (typeof to== 'number' && typeof data.splice == 'function'){	// is array
      data = {
        total:to,
        rows: data,
        wh:wh
      }
      i=2;
    }
    var dg = $(this);
    var opts = dg.datagrid('options');
    var pager = dg.datagrid('getPager');
    pager.pagination({
      onSelectPage:function(pageNum, pageSize){
        opts.pageNumber = pageNum;
        opts.pageSize = pageSize;
        pager.pagination('refresh',{
          pageNumber:pageNum,
          pageSize:pageSize
        });
        var start = (opts.pageNumber-1)*parseInt(opts.pageSize);
//    var end = start + parseInt(opts.pageSize);
        data.rows = (getData(start,parseInt(opts.pageSize),wh));
        dg.datagrid('loadData',data);
      }
    });
    return data;
  }

  $(function(){
    $('#dg').datagrid({
      toolbar:[
        {
          text:'删除所选中的一条信息',
          iconCls:'icon-remove',
          handler:function(){
            $('#test').window('open');
          }
        },
        {
          text:'给教师分配角色',
          iconCls:'icon-search',
          handler:function(){
            var row = $('#dg').datagrid('getSelected');
            $("#teacherId").val(row.teacherId);
            document.getElementById("teacherId1").innerHTML=""+row.teacherId+"";
            document.getElementById("teacherName").innerHTML=""+row.teacherName+"";
            $('#test1').window('open');
          }
        }
      ]})

    $('#dg').datagrid({loadFilter:pagerFilter}).datagrid('loadData', getData(0,10,""));
  });
  function delStudent(){
    var row = $('#dg').datagrid('getSelected');
    if (delData(row.teacherId)==200){
      $('#test').window('close');
    }else{
      alert("删除失败")
    }
  }
  function delData(s){
    var code1 = 0;
    $.ajax({
      method : 'GET',
      url : 'rest/page/manageShiro/delTeaRole?manageId=${user.teacherid}&teacherId='+s+'',
      async : false,
      dataType : 'json',
      success : function(code) {
        code1 = code.code
        if(code.code == 200){
          $.messager.show({title:'操作提示',msg:code.message+"请点击表单下刷新按钮刷新显示",showType:'show',style: {
            top:($(window).height()-200) * 0.5,
            left:($(window).width() -250) * 0.5
          }});
        }else{
          $.messager.show({title:'操作提示',msg:code.message,showType:'show',style: {
            top:($(window).height()-200) * 0.5,
            left:($(window).width() -250) * 0.5
          }});
        }
      },
      error : function() {
        alert('error');
      }
    });
    return code1
  }

  function getData(r,p,s){
    var infor_data = [];
    var total = 0;
    $.ajax({
      method : 'POST',
      url : 'rest/page/manageShiro/selAllTeaRole',
      data:{"startrow":r,"pageSize":p,"teacherId": s},
      async : false,
      dataType : 'json',
      success : function(data) {
        infor_data = data.data
        total = data.total
      },
      error : function() {
        alert('error');
      }
    });
    var rows = [];
    for(var i=0; i< infor_data.length; i++){
      rows.push({
        total:total,
        wh:s,
        teacherId:infor_data[i].teacherId,
        teacherName:infor_data[i].teacherName,
        teacherIdCard:infor_data[i].teacherIdCard,
        teacherSchool:infor_data[i].teacherSchool,
        teacherCollege:infor_data[i].teacherCollege,
        roles:infor_data[i].roles,
        teacherSex:infor_data[i].teacherSex
      });
    }
    return rows;
  }

  function doSearch(value){
    var value1 = value+""
    i = 1;
    $('#dg').datagrid({loadFilter:pagerFilter}).datagrid('loadData', getData(0,10,value1));
  }

  function submitForm() {
    $('#ff').form('submit', {
      url : 'rest/page/manageShiro/addTeaRole',
      success : function(data){
        var obj = JSON.parse(data)
        if(obj.code == 200){
          $.messager.show({title:'操作提示',msg:obj.message+"请点击表单下刷新按钮刷新显示",showType:'show',style: {
            top:($(window).height()-200) * 0.5,
            left:($(window).width() -250) * 0.5
          }});
          $('#test1').window('close');
        }else{
          $.messager.show({title:'操作提示',msg:obj.message,showType:'show',style: {
            top:($(window).height()-200) * 0.5,
            left:($(window).width() -250) * 0.5
          }});
        }
      }
    });
  }
</script>
</body>

</html>
